import React, { Component } from 'react'
import Header from "../../components/Header/Header"
import {reqcartlist} from "../../http/api"
import { $pre } from '../../http/http'
import "./Shop.less"
import yImg from "../../assets/img/y.jpeg"
import nImg from "../../assets/img/n.jpeg"
import { Button } from 'antd-mobile'
export default class Shop extends Component {
  constructor(){
    super()
    this.state={
      //1.初始值
      arr:[]
    }
  }
  componentDidMount(){
    //2.发请求
    this.getList()
  }
  //请求列表
  async getList(){
    let res =await reqcartlist({
      uid:JSON.parse(sessionStorage.getItem('userInfo')).uid
    })
    if(res.data.code == 200){
      let arr = res.data.list[1].content?res.data.list[1].content:[]
      //补checked
      arr.forEach(item=>{
        item.checked=false
      })
      this.setState({
        arr:arr,
      })
    }
  }
  render() {
    let {arr} = this.state
    return (
      <div className='shop'>
          <Header title="购物车"></Header>
          {

            arr.map((item,index)=>{
             return (
             <div className='item' key={item.id}>
               <img className='checkbox' src={true?yImg:nImg} alt="" />
               <img className='img' src={$pre+item.img} alt="" />
                <div className='right'>
                  <h3>name:xx</h3>
                  <div>price:xx</div>
                  <div>
                    <Button>-</Button>
                    1
                    <Button>+</Button>
                  </div>
                </div>
                <div className='del'>
                  <Button color='danger'>删除</Button>
                </div>
             </div>
             )
            })
          }
      </div>
    )
  }
}
